package com.jash.myutils.utils;//

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

// Created by YoungKaka on 2016/9/2.
// 我的心愿是:世界和平
//
public class BitmapCompressUtils {
    public static Bitmap compressBitmap(int widthPixel, int heightPixel, byte[] bs) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeByteArray(bs, 0, bs.length, options);
        int height = options.outHeight;
        int width = options.outWidth;
        int widScale = (int) (widthPixel * 1.0 / width + 0.5f);
        int heightScale = (int) (heightPixel * 1.0 / height + 0.5f);
        int scale = widScale > height ? widScale : heightScale;
        if (scale > 1) {
            options.inSampleSize = scale;
        }
        options.inPreferredConfig = Bitmap.Config.RGB_565;
        options.inJustDecodeBounds = false;
        Bitmap bitmap = BitmapFactory.decodeByteArray(bs, 0, bs.length, options);
        return bitmap;
    }
}
